#pragma once
#include"Button.h"

class CMenu
{
	//Menu Variables-----------------------------------------------//
private:
	//gary added an array of button_textures
	IDirect3DTexture9*	m_ButtonTexture[NumberOfButtons];			//Texture//
	D3DXIMAGE_INFO		m_ButtonInfo;				//Texture Info//
	CButton				m_Buttons[NumberOfButtons];	//Menu Buttons: Play, Options, Credits, Quit//
	LPD3DXMESH			m_ButtonMesh;				//Mesh Used as Button//

	//Menu Functions-----------------------------------------------//
public:
	//Constructor//
	CMenu(){};
	//Initilize Menu//
	void InitMenu(LPDIRECT3DDEVICE9& D3DDevice)
	{
		//D3DXCreateBox(D3DDevice, 
		//	6.0f, //Width	(X)//
		//	3.0f, //Height	(Y)//
		//	2.0f, //Depth	(Z)//
		//	&m_ButtonMesh, //Mesh Pointer//
		//	0);	//Adjacency//


		D3DXLoadMeshFromX(L"Meshes/menuBox.X", D3DXMESH_MANAGED, D3DDevice,
			NULL, NULL, NULL, NULL, &m_ButtonMesh);



		//gary added --hard coded in the textures

		//Create the Texture that will overlay the vertices//
		D3DXCreateTextureFromFile( D3DDevice,	//The Direct3D device dereference//
			L"Textures/TileRed.jpg",						//The filename of the texture//
			&m_ButtonTexture[0]);					//Location we are storing the texture//

		//Create the Texture that will overlay the vertices//
		D3DXCreateTextureFromFile( D3DDevice,	//The Direct3D device dereference//
			L"Textures/TileYellow.jpg",						//The filename of the texture//
			&m_ButtonTexture[1]);					//Location we are storing the texture//
		//Create the Texture that will overlay the vertices//
		D3DXCreateTextureFromFile( D3DDevice,	//The Direct3D device dereference//
			L"Textures/TileBlue.jpg",						//The filename of the texture//
			&m_ButtonTexture[2]);					//Location we are storing the texture//
		//Create the Texture that will overlay the vertices//
		D3DXCreateTextureFromFile( D3DDevice,	//The Direct3D device dereference//
			L"Textures/TilePurple.jpg",						//The filename of the texture//
			&m_ButtonTexture[3]);					//Location we are storing the texture//

		



		//Initiliaze the buttons//
		for(int buttonIndex = 0; buttonIndex < NumberOfButtons; buttonIndex++)
		{
			m_Buttons[buttonIndex].setPosition(0.0f, (4.0f - (buttonIndex*3.5f)));
			m_Buttons[buttonIndex].SetStateIdle();
			//On Screen Coordinates of the right a left side of the buttons//
			m_Buttons[buttonIndex].SetRECTX(294, 506);
			//Set up the unique button elements//
			switch(buttonIndex)
			{
			case 0:
				m_Buttons[buttonIndex].setText(L"Play");
				m_Buttons[buttonIndex].SetRECTY(61, 162);
				break;
			case 1:
				m_Buttons[buttonIndex].setText(L"Rules");
				m_Buttons[buttonIndex].SetRECTY(190, 290);
				break;
			case 2:
				m_Buttons[buttonIndex].setText(L"Credits");
				m_Buttons[buttonIndex].SetRECTY(319, 419);
				break;
			case 3:
				m_Buttons[buttonIndex].setText(L"Quit");
				m_Buttons[buttonIndex].SetRECTY(447, 548);
				break;
			default:
				m_Buttons[buttonIndex].setText(L"Broken");
			}
		}
	}
	//gary changed so it could take in the array index with  "int"
	void setTexture(int num,IDirect3DTexture9* temp)
	{
		m_ButtonTexture[num] = temp;
	}
	//gary changed so it could take in the array index with  "int"
	IDirect3DTexture9* getTexture(int num)
	{
		return m_ButtonTexture[num];
	}
	D3DXIMAGE_INFO getInfo(void)
	{
		return m_ButtonInfo;
	}

	CButton& getButton(int buttonNumber)
	{
		return m_Buttons[buttonNumber];
	}

	LPD3DXMESH& getMesh(void)
	{
		return m_ButtonMesh;
	}

	//Destructor//
	~CMenu()
	{
		//Release the Mesh//
		if(m_ButtonMesh)
		{
			m_ButtonMesh->Release();
			m_ButtonMesh = 0;
		}

		//Clean the Text for the Buttons// Not sure if this is necessary//
		for(int buttonIndex = 0; buttonIndex < NumberOfButtons; buttonIndex++)
		{
			m_Buttons[buttonIndex].CleanUp();
		}

		//Release the Texture//
		//gary fixed so it could account for new array of textures
		for(int button = 0; button < NumberOfButtons; button++)
		{
			if(m_ButtonTexture[button])
			{
				m_ButtonTexture[button]->Release();
				m_ButtonTexture[button] = 0;
			}
		}
		
	}
};